<template>
  <div id="app">
    <!-- 侧边栏导航组件 -->
    <Sidebar />

    <!-- 主要内容区域 -->
    <main class="main-content">
      <router-view />
    </main>

    <!-- 回到顶部按钮 -->
    <button v-if="showScrollTop" @click="scrollToTop" class="scroll-top-btn">
      ↑
    </button>
  </div>
</template>

<script>
import Sidebar from './components/Sidebar.vue'

export default {
  name: 'App',
  components: {
    Sidebar
  },
  data() {
    return {
      showScrollTop: false
    }
  },
  mounted() {
    window.addEventListener('scroll', this.handleScroll)
  },
  beforeUnmount() {
    window.removeEventListener('scroll', this.handleScroll)
  },
  methods: {
    handleScroll() {
      this.showScrollTop = window.scrollY > 300
    },
    scrollToTop() {
      window.scrollTo({
        top: 0,
        behavior: 'smooth'
      })
    }
  }
}
</script>

<style>
/* 全局样式重置 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
    'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
    sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background-color: #f8f9fa;
  color: #333;
}

#app {
  display: flex;
}

/* 主要内容区域 */
.main-content {
  flex: 1;
  margin-left: 250px;
  padding: 20px 30px;
  min-height: 100vh;
  width: calc(100vw - 250px);
  overflow-x: auto;
}

/* 回到顶部按钮 */
.scroll-top-btn {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background-color: #ff9a9e;
  color: #fff;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  transition: all 0.3s ease;
  z-index: 999;
}

.scroll-top-btn:hover {
  background-color: #f86d75;
  transform: translateY(-3px);
}

/* 响应式设计 */
@media (max-width: 768px) {
  .main-content {
    margin-left: 70px;
    padding: 10px;
  }
}

@media (max-width: 480px) {
  .main-content {
    margin-left: 0;
    padding: 10px;
  }
  
  .scroll-top-btn {
    bottom: 1rem;
    right: 1rem;
    width: 40px;
    height: 40px;
    font-size: 1.2rem;
  }
}
</style>